﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model.Course;
using Model.User;
using System.Web.UI.HtmlControls;

public partial class ViewCourseUnlogged : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["CourseId"] == null) return;

        if (Teacher.get(Convert.ToInt32(Session["Person"])) != null)
            toolbarButtonAddLecture.Visible = true;

        Course c = Course.get(Convert.ToInt32(Session["CourseId"]));

        if (c != null)
        {
            courseNameLabel.Text = c.getName();
            courseNameLabel.Font.Size = FontUnit.Parse("1.5em");
            lecturerLabel.Text = "Prowadzący: " + c.getLecturer().getFirstName() + " " + c.getLecturer().getLastName();

            Lecture[] lectures = Lecture.getLectures(c);

            foreach (Lecture l in lectures)
            {
                LinkButton lectureButton = new LinkButton();

                lectureButton.Text = l.getName();
                lectureButton.CommandArgument = l.getId().ToString();
                lectureButton.Command += lectureButton_Command;


                LecturesContent.Controls.Add(lectureButton);
                LecturesContent.Controls.Add(new HtmlGenericControl("br"));
            }
        }
    }

    void lectureButton_Command(object sender, CommandEventArgs e)
    {
        Session["LectureId"] = e.CommandArgument;
        Session["ActiveMenuButton"] = "menuButton6";
        Response.Redirect("~/CourseView/ViewLecture.aspx");
    }

    protected void toolbarButtonAddLecture_Command(object sender, CommandEventArgs e)
    {
        Session["ActiveMenuButton"] = "menuButton6";
        Response.Redirect((string)e.CommandArgument);
    }
}